#include "gamecontroller.h"
#include "gameconfig.h"
#include <QSound>


GameController *GameController::s_instance = nullptr;
GameController::GameController()
    : m_mainScene(nullptr)
    , m_levelSence(nullptr)
    , m_gameScene(nullptr)
{

}

GameController::~GameController()
{
    //    if(nullptr != s_instance)
    //    {
    //        delete s_instance;
    //    }

    //    if(nullptr != m_mainScene)
    //    {
    //        delete m_mainScene;
    //    }
    //    if(nullptr != m_gameScene)
    //    {
    //        delete m_gameScene;
    //    }
    //    if(nullptr != m_levelSence)
    //    {
    //        delete m_levelSence;
    //    }
}

GameController *GameController::getInstance()
{
    if(s_instance == nullptr)
    {
        s_instance = new GameController;
    }
    return  s_instance;
}

void GameController::initMainScene(MainScene *scene)
{
    m_mainScene = scene;
    //saveAdress = m_mainScene->geometry();
    //m_mainScene->move(m_curPos);
}


// 界面转换
void GameController::showMainScene()
{
    if(nullptr != m_mainScene)
    {
        m_mainScene->move(m_curPos);
        m_mainScene->show();
        //m_mainScene->setGeometry(saveAdress);

    }
}

void GameController::hideMainScene()
{
    if(nullptr != m_mainScene)
    {
        m_curPos = m_mainScene->pos();
        m_mainScene->hide();
        //saveAdress = m_mainScene->geometry();

    }
}

void GameController::showLevelScene()
{
    if(nullptr == m_levelSence)
    {
        m_levelSence = new LevelSence();
    }
    m_levelSence->move(m_curPos);
    m_levelSence->show();
    //m_levelSence->setGeometry(saveAdress);

}

void GameController::hideLevelScene()
{
    if(nullptr != m_levelSence)
    {
         m_curPos = m_levelSence->pos();
        m_levelSence->hide();
        //saveAdress = m_levelSence->geometry();

    }
}

void GameController::showGameScene(int level)
{
    if(nullptr == m_gameScene)
    {
        m_gameScene = new GameScene(level);
    }
    m_gameScene->move(m_curPos);
    m_gameScene->show();
    //m_gameScene->setGeometry(saveAdress);

}

void GameController::hideGameScene()
{
    if(nullptr != m_gameScene)
    {
        m_curPos = m_gameScene->pos();
        m_gameScene->hide();
        //saveAdress = m_gameScene->geometry();

    }
}

void GameController::deleteGameScene()
{
    if(nullptr != m_gameScene)
    {
        m_curPos = m_gameScene->pos();
        delete  m_gameScene;
        //saveAdress = m_gameScene->geometry();
    }
    m_gameScene = nullptr;
}

void GameController::playStartSound()
{
    QSound::play(SOUND_TAP_BUTTON);
}

void GameController::playBackSound()
{
    QSound::play(SOUND_BACK_BUTTON);
}

void GameController::playFlipCoinSound()
{
    QSound::play(SOUND_COIN_FLIP);
}

void GameController::playWinSound()
{
    QSound::play(SOUND_LEVEL_WIN);
}


